import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { sysMDept } from "@/api/backend/index";
import { handleTree } from "@/utils/common";

export const useDept = defineStore(Names.dept, {
  state: () => {
    return {
      type: [],
      tags: <any>{},
    };
  },
  getters: {},
  actions: {
    //获取部门下拉框列表信息
    getDept() {
      return new Promise((resolve, reject) => {
        _get(sysMDept + "/treeselect", {}, "json", "")
          .then((res) => {
            console.log(res);
            resolve(res);
          })
          .catch((err) => {
            console.log(err);
            reject(err);
          });
      });
    },
    //获取原始部门数据进行树型再造
    getDeptOrigin() {
      return new Promise((resolve, reject) => {
        _get(sysMDept + "/list", {}, "json", "")
          .then((res: any) => {
            let data = handleTree(res.data, "deptId", "", "");
            console.log("获取原始部门数据进行树型再造", res);
            resolve(data);
          })
          .catch((err: any) => {
            console.log(err);
            reject(err);
          });
      });
    },
  },
});
